﻿namespace ExamV5.ManagSys
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmSetUserPower : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected CheckBox CBAddBook;
        protected CheckBox CBAddExam;
        protected CheckBox CBAddForum;
        protected CheckBox CBAddLession;
        protected CheckBox CBAddNews;
        protected CheckBox CBAddPaper;
        protected CheckBox CBAddPoll;
        protected CheckBox CBAddRubric;
        protected CheckBox CBAddStudyPlan;
        protected CheckBox CBAddSubject;
        protected CheckBox CBCheckA;
        protected CheckBox CBCheckAN;
        protected CheckBox CBCheckC;
        protected CheckBox CBCheckF;
        protected CheckBox CBCheckJ;
        protected CheckBox CBCheckO;
        protected CheckBox CBCheckPaper;
        protected CheckBox CBCheckRubric;
        protected CheckBox CBCheckT;
        protected CheckBox CBGradeFolder;
        protected CheckBox CBLookAllPaper;
        protected CheckBox CBLookPaper;
        protected CheckBox CBManagBook;
        protected CheckBox CBManagExam;
        protected CheckBox CBManagForum;
        protected CheckBox CBManagLession;
        protected CheckBox CBManagNews;
        protected CheckBox CBManagPaper;
        protected CheckBox CBManagPoll;
        protected CheckBox CBManagRubric;
        protected CheckBox CBManagStudyPlan;
        protected CheckBox CBManagSubject;
        protected CheckBox CBManagUser;
        protected CheckBox CBPaperTemp;
        protected CheckBox CBSysMenu;
        protected CheckBox CBSysSet;
        protected CheckBox CBUserPower;
        protected CheckBox CBZiManag;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        protected Label labCheckMXPaper;
        protected Label labSetMXPaper;
        protected Label labUserInfo;
        private PublicFun publicFun_0 = new PublicFun();

        protected void butDefault_Click(object sender, EventArgs e)
        {
            string strSql = "";
            strSql = "update UserPower ";
            if (this.CBLookPaper.Checked)
            {
                strSql = strSql + " set LookPaper='Y'";
            }
            else
            {
                strSql = strSql + " set LookPaper='N'";
            }
            if (this.CBAddNews.Checked)
            {
                strSql = strSql + " ,AddNews='Y'";
            }
            else
            {
                strSql = strSql + " ,AddNews='N'";
            }
            if (this.CBAddExam.Checked)
            {
                strSql = strSql + " ,AddExam='Y'";
            }
            else
            {
                strSql = strSql + " ,AddExam='N'";
            }
            if (!this.CBManagNews.Checked)
            {
                strSql = strSql + " ,ManagNews='N'";
            }
            else
            {
                strSql = strSql + " ,ManagNews='Y'";
            }
            if (!this.CBAddForum.Checked)
            {
                strSql = strSql + " ,AddForum='N'";
            }
            else
            {
                strSql = strSql + " ,AddForum='Y'";
            }
            if (this.CBManagForum.Checked)
            {
                strSql = strSql + " ,ManagForum='Y'";
            }
            else
            {
                strSql = strSql + " ,ManagForum='N'";
            }
            if (this.CBAddPoll.Checked)
            {
                strSql = strSql + " ,AddPoll='Y'";
            }
            else
            {
                strSql = strSql + " ,AddPoll='N'";
            }
            if (!this.CBManagPoll.Checked)
            {
                strSql = strSql + " ,ManagPoll='N'";
            }
            else
            {
                strSql = strSql + " ,ManagPoll='Y'";
            }
            if (this.CBAddBook.Checked)
            {
                strSql = strSql + " ,AddText='Y'";
            }
            else
            {
                strSql = strSql + " ,AddText='N'";
            }
            if (!this.CBManagBook.Checked)
            {
                strSql = strSql + " ,ManagText='N'";
            }
            else
            {
                strSql = strSql + " ,ManagText='Y'";
            }
            if (this.CBAddLession.Checked)
            {
                strSql = strSql + " ,AddLession='Y'";
            }
            else
            {
                strSql = strSql + " ,AddLession='N'";
            }
            if (this.CBManagLession.Checked)
            {
                strSql = strSql + " ,ManagLession='Y'";
            }
            else
            {
                strSql = strSql + " ,ManagLession='N'";
            }
            if (!this.CBAddStudyPlan.Checked)
            {
                strSql = strSql + " ,AddStudyPlan='N'";
            }
            else
            {
                strSql = strSql + " ,AddStudyPlan='Y'";
            }
            if (this.CBManagStudyPlan.Checked)
            {
                strSql = strSql + " ,ManagStudyPlan='Y'";
            }
            else
            {
                strSql = strSql + " ,ManagStudyPlan='N'";
            }
            if (!this.CBAddSubject.Checked)
            {
                strSql = strSql + " ,AddSubject='N'";
            }
            else
            {
                strSql = strSql + " ,AddSubject='Y'";
            }
            if (!this.CBManagSubject.Checked)
            {
                strSql = strSql + " ,ManagSubject='N'";
            }
            else
            {
                strSql = strSql + " ,ManagSubject='Y'";
            }
            if (!this.CBAddRubric.Checked)
            {
                strSql = strSql + " ,AddRubric='N'";
            }
            else
            {
                strSql = strSql + " ,AddRubric='Y'";
            }
            if (!this.CBManagRubric.Checked)
            {
                strSql = strSql + " ,ManagRubric='N'";
            }
            else
            {
                strSql = strSql + " ,ManagRubric='Y'";
            }
            if (!this.CBCheckRubric.Checked)
            {
                strSql = strSql + " ,CheckRubric='N'";
            }
            else
            {
                strSql = strSql + " ,CheckRubric='Y'";
            }
            if (!this.CBAddPaper.Checked)
            {
                strSql = strSql + " ,AddPaper='N'";
            }
            else
            {
                strSql = strSql + " ,AddPaper='Y'";
            }
            if (!this.CBManagPaper.Checked)
            {
                strSql = strSql + " ,ManagPaper='N'";
            }
            else
            {
                strSql = strSql + " ,ManagPaper='Y'";
            }
            if (this.CBCheckPaper.Checked)
            {
                strSql = strSql + " ,CheckPaper='Y'";
            }
            else
            {
                strSql = strSql + " ,CheckPaper='N'";
            }
            if (!this.CBPaperTemp.Checked)
            {
                strSql = strSql + " ,PaperTemple='N'";
            }
            else
            {
                strSql = strSql + " ,PaperTemple='Y'";
            }
            if (this.CBCheckF.Checked)
            {
                strSql = strSql + " ,CheckRubricF='Y'";
            }
            else
            {
                strSql = strSql + " ,CheckRubricF='N'";
            }
            if (!this.CBCheckO.Checked)
            {
                strSql = strSql + " ,CheckRubricO='N'";
            }
            else
            {
                strSql = strSql + " ,CheckRubricO='Y'";
            }
            if (!this.CBCheckA.Checked)
            {
                strSql = strSql + " ,CheckRubricA='N'";
            }
            else
            {
                strSql = strSql + " ,CheckRubricA='Y'";
            }
            if (!this.CBCheckC.Checked)
            {
                strSql = strSql + " ,CheckRubricC='N'";
            }
            else
            {
                strSql = strSql + " ,CheckRubricC='Y'";
            }
            if (!this.CBCheckT.Checked)
            {
                strSql = strSql + " ,CheckRubricT='N'";
            }
            else
            {
                strSql = strSql + " ,CheckRubricT='Y'";
            }
            if (this.CBCheckAN.Checked)
            {
                strSql = strSql + " ,CheckRubricAN='Y'";
            }
            else
            {
                strSql = strSql + " ,CheckRubricAN='N'";
            }
            if (!this.CBCheckJ.Checked)
            {
                strSql = strSql + " ,CheckRubricJ='N'";
            }
            else
            {
                strSql = strSql + " ,CheckRubricJ='Y'";
            }
            if (!this.CBManagExam.Checked)
            {
                strSql = strSql + " ,ManagExam='N'";
            }
            else
            {
                strSql = strSql + " ,ManagExam='Y'";
            }
            if (this.CBZiManag.Checked)
            {
                strSql = strSql + " ,ZiManag='Y'";
            }
            else
            {
                strSql = strSql + " ,ZiManag='N'";
            }
            if (!this.CBManagUser.Checked)
            {
                strSql = strSql + " ,ManagUser='N'";
            }
            else
            {
                strSql = strSql + " ,ManagUser='Y'";
            }
            if (this.CBSysMenu.Checked)
            {
                strSql = strSql + " ,ManagMenu='Y'";
            }
            else
            {
                strSql = strSql + " ,ManagMenu='N'";
            }
            if (this.CBSysSet.Checked)
            {
                strSql = strSql + " ,ManagSysSet='Y'";
            }
            else
            {
                strSql = strSql + " ,ManagSysSet='N'";
            }
            if (!this.CBGradeFolder.Checked)
            {
                strSql = strSql + " ,ManagFolder='N'";
            }
            else
            {
                strSql = strSql + " ,ManagFolder='Y'";
            }
            if (this.CBUserPower.Checked)
            {
                strSql = strSql + " ,ManagPower='Y'";
            }
            else
            {
                strSql = strSql + " ,ManagPower='N'";
            }
            strSql = strSql + " where UserCode='" + this.ViewState["UserCode"].ToString() + "'";
            if (this.CBLookAllPaper.Enabled)
            {
                if (!this.CBLookAllPaper.Checked)
                {
                    strSql = strSql + ";update UserPower set LookPaper='N' where UserCode<>'" + this.ViewState["UserCode"].ToString() + "'";
                }
                else
                {
                    strSql = strSql + ";update UserPower set LookPaper='Y' where UserCode<>'" + this.ViewState["UserCode"].ToString() + "'";
                }
            }
            this.publicFun_0.ExecuteSql(strSql);
            base.Response.Write("<script>alert('设置权限操作成功！')</script>");
        }

        private void method_0()
        {
            try
            {
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                SqlCommand command = new SqlCommand("select a.UserCode,a.UserName,b.AddExam,b.AddStudyPlan,b.ManagStudyPlan,a.UserLevel,b.AddNews,b.ManagNews,b.AddForum,b.ManagForum,b.AddPoll,b.ManagPoll,b.AddRubric,b.ManagRubric,b.AddSubject,b.ManagSubject,b.AddText,b.ManagText,b.AddLession,b.ManagLession,b.CheckRubric,b.AddPaper,b.ManagPaper,b.CheckPaper,b.PaperTemple,b.LookPaper,b.CheckRubricF,b.CheckRubricO,b.CheckRubricA,b.CheckRubricC,b.CheckRubricT,b.CheckRubricAN,b.CheckRubricJ,b.ManagExam,b.ManagUser,b.ManagMenu,b.ManagSysSet,b.ManagFolder,b.ManagPower,b.ManagRacing,b.ZiManag from UserInfo a,UserPower b where a.UserCode=b.UserCode and a.ID=" + this.int_0, connection);
                connection.Open();
                SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
                if (reader.Read())
                {
                    this.ViewState["UserCode"] = reader["UserCode"].ToString();
                    this.labUserInfo.Text = "设置用户〖" + reader["UserName"].ToString() + "(" + reader["UserCode"].ToString() + ")〗权限信息";
                    if (reader["UserCode"].ToString() == "admin")
                    {
                        this.CBUserPower.Enabled = false;
                    }
                    if (!(reader["LookPaper"].ToString() == "Y"))
                    {
                        this.CBLookPaper.Checked = false;
                    }
                    else
                    {
                        this.CBLookPaper.Checked = true;
                    }
                    this.labSetMXPaper.Text = string.Concat(new object[] { "<a href='#' onclick=javascript:SetUserPower('", this.int_0, "','L')>", this.labSetMXPaper.Text, "</a>" });
                    if (reader["UserLevel"].ToString() == "A")
                    {
                        this.CBAddNews.Enabled = false;
                        this.CBManagNews.Enabled = false;
                        this.CBAddForum.Enabled = false;
                        this.CBManagForum.Enabled = false;
                        this.CBAddPoll.Enabled = false;
                        this.CBManagPoll.Enabled = false;
                        this.CBAddBook.Enabled = false;
                        this.CBManagBook.Enabled = false;
                        this.CBAddLession.Enabled = false;
                        this.CBManagLession.Enabled = false;
                        this.CBAddStudyPlan.Enabled = false;
                        this.CBManagStudyPlan.Enabled = false;
                        this.CBAddSubject.Enabled = false;
                        this.CBManagSubject.Enabled = false;
                        this.CBAddRubric.Enabled = false;
                        this.CBManagRubric.Enabled = false;
                        this.CBCheckRubric.Enabled = false;
                        this.CBAddPaper.Enabled = false;
                        this.CBManagPaper.Enabled = false;
                        this.CBCheckPaper.Enabled = false;
                        this.CBPaperTemp.Enabled = false;
                        this.CBLookAllPaper.Enabled = false;
                        this.CBCheckF.Enabled = false;
                        this.CBCheckA.Enabled = false;
                        this.CBCheckC.Enabled = false;
                        this.CBCheckT.Enabled = false;
                        this.CBCheckAN.Enabled = false;
                        this.CBCheckO.Enabled = false;
                        this.CBCheckJ.Enabled = false;
                        this.CBManagExam.Enabled = false;
                        this.CBAddExam.Enabled = false;
                        this.CBZiManag.Enabled = false;
                        this.CBManagUser.Enabled = false;
                        this.CBSysSet.Enabled = false;
                        this.CBGradeFolder.Enabled = false;
                        this.CBSysMenu.Enabled = false;
                        this.CBUserPower.Enabled = false;
                    }
                    else
                    {
                        this.labCheckMXPaper.Text = string.Concat(new object[] { "<a href='#' onclick=javascript:SetUserPower('", this.int_0, "','C')>", this.labCheckMXPaper.Text, "</a>" });
                        if (reader["AddNews"].ToString() == "Y")
                        {
                            this.CBAddNews.Checked = true;
                        }
                        else
                        {
                            this.CBAddNews.Checked = false;
                        }
                        if (!(reader["AddExam"].ToString() == "Y"))
                        {
                            this.CBAddExam.Checked = false;
                        }
                        else
                        {
                            this.CBAddExam.Checked = true;
                        }
                        if (reader["ManagNews"].ToString() == "Y")
                        {
                            this.CBManagNews.Checked = true;
                        }
                        else
                        {
                            this.CBManagNews.Checked = false;
                        }
                        if (!(reader["AddForum"].ToString() == "Y"))
                        {
                            this.CBAddForum.Checked = false;
                        }
                        else
                        {
                            this.CBAddForum.Checked = true;
                        }
                        if (reader["ManagForum"].ToString() == "Y")
                        {
                            this.CBManagForum.Checked = true;
                        }
                        else
                        {
                            this.CBManagForum.Checked = false;
                        }
                        if (!(reader["AddPoll"].ToString() == "Y"))
                        {
                            this.CBAddPoll.Checked = false;
                        }
                        else
                        {
                            this.CBAddPoll.Checked = true;
                        }
                        if (reader["ManagPoll"].ToString() == "Y")
                        {
                            this.CBManagPoll.Checked = true;
                        }
                        else
                        {
                            this.CBManagPoll.Checked = false;
                        }
                        if (!(reader["AddText"].ToString() == "Y"))
                        {
                            this.CBAddBook.Checked = false;
                        }
                        else
                        {
                            this.CBAddBook.Checked = true;
                        }
                        if (!(reader["ManagText"].ToString() == "Y"))
                        {
                            this.CBManagBook.Checked = false;
                        }
                        else
                        {
                            this.CBManagBook.Checked = true;
                        }
                        if (!(reader["AddLession"].ToString() == "Y"))
                        {
                            this.CBAddLession.Checked = false;
                        }
                        else
                        {
                            this.CBAddLession.Checked = true;
                        }
                        if (!(reader["ManagLession"].ToString() == "Y"))
                        {
                            this.CBManagLession.Checked = false;
                        }
                        else
                        {
                            this.CBManagLession.Checked = true;
                        }
                        if (!(reader["AddStudyPlan"].ToString() == "Y"))
                        {
                            this.CBAddStudyPlan.Checked = false;
                        }
                        else
                        {
                            this.CBAddStudyPlan.Checked = true;
                        }
                        if (!(reader["ManagStudyPlan"].ToString() == "Y"))
                        {
                            this.CBManagStudyPlan.Checked = false;
                        }
                        else
                        {
                            this.CBManagStudyPlan.Checked = true;
                        }
                        if (reader["AddSubject"].ToString() == "Y")
                        {
                            this.CBAddSubject.Checked = true;
                        }
                        else
                        {
                            this.CBAddSubject.Checked = false;
                        }
                        if (!(reader["ManagSubject"].ToString() == "Y"))
                        {
                            this.CBManagSubject.Checked = false;
                        }
                        else
                        {
                            this.CBManagSubject.Checked = true;
                        }
                        if (reader["AddRubric"].ToString() == "Y")
                        {
                            this.CBAddRubric.Checked = true;
                        }
                        else
                        {
                            this.CBAddRubric.Checked = false;
                        }
                        if (!(reader["ManagRubric"].ToString() == "Y"))
                        {
                            this.CBManagRubric.Checked = false;
                        }
                        else
                        {
                            this.CBManagRubric.Checked = true;
                        }
                        if (reader["CheckRubric"].ToString() == "Y")
                        {
                            this.CBCheckRubric.Checked = true;
                        }
                        else
                        {
                            this.CBCheckRubric.Checked = false;
                        }
                        if (!(reader["AddPaper"].ToString() == "Y"))
                        {
                            this.CBAddPaper.Checked = false;
                        }
                        else
                        {
                            this.CBAddPaper.Checked = true;
                        }
                        if (!(reader["ManagPaper"].ToString() == "Y"))
                        {
                            this.CBManagPaper.Checked = false;
                        }
                        else
                        {
                            this.CBManagPaper.Checked = true;
                        }
                        if (!(reader["CheckPaper"].ToString() == "Y"))
                        {
                            this.CBCheckPaper.Checked = false;
                        }
                        else
                        {
                            this.CBCheckPaper.Checked = true;
                        }
                        if (!(reader["PaperTemple"].ToString() == "Y"))
                        {
                            this.CBPaperTemp.Checked = false;
                        }
                        else
                        {
                            this.CBPaperTemp.Checked = true;
                        }
                        if (this.publicFun_0.GetValues("select UserCode from UserPower where LookPaper='N'", "UserCode") != "")
                        {
                            this.CBLookAllPaper.Checked = false;
                        }
                        else
                        {
                            this.CBLookAllPaper.Checked = true;
                        }
                        if (!(reader["CheckRubricF"].ToString() == "Y"))
                        {
                            this.CBCheckF.Checked = false;
                        }
                        else
                        {
                            this.CBCheckF.Checked = true;
                        }
                        if (reader["CheckRubricO"].ToString() == "Y")
                        {
                            this.CBCheckO.Checked = true;
                        }
                        else
                        {
                            this.CBCheckO.Checked = false;
                        }
                        if (!(reader["CheckRubricA"].ToString() == "Y"))
                        {
                            this.CBCheckA.Checked = false;
                        }
                        else
                        {
                            this.CBCheckA.Checked = true;
                        }
                        if (!(reader["CheckRubricC"].ToString() == "Y"))
                        {
                            this.CBCheckC.Checked = false;
                        }
                        else
                        {
                            this.CBCheckC.Checked = true;
                        }
                        if (!(reader["CheckRubricT"].ToString() == "Y"))
                        {
                            this.CBCheckT.Checked = false;
                        }
                        else
                        {
                            this.CBCheckT.Checked = true;
                        }
                        if (reader["CheckRubricAN"].ToString() == "Y")
                        {
                            this.CBCheckAN.Checked = true;
                        }
                        else
                        {
                            this.CBCheckAN.Checked = false;
                        }
                        if (!(reader["CheckRubricJ"].ToString() == "Y"))
                        {
                            this.CBCheckJ.Checked = false;
                        }
                        else
                        {
                            this.CBCheckJ.Checked = true;
                        }
                        if (!(reader["ManagExam"].ToString() == "Y"))
                        {
                            this.CBManagExam.Checked = false;
                        }
                        else
                        {
                            this.CBManagExam.Checked = true;
                        }
                        if (!(reader["ZiManag"].ToString() == "Y"))
                        {
                            this.CBZiManag.Checked = false;
                        }
                        else
                        {
                            this.CBZiManag.Checked = true;
                        }
                        if (!(reader["ManagUser"].ToString() == "Y"))
                        {
                            this.CBManagUser.Checked = false;
                        }
                        else
                        {
                            this.CBManagUser.Checked = true;
                        }
                        if (!(reader["ManagMenu"].ToString() == "Y"))
                        {
                            this.CBSysMenu.Checked = false;
                        }
                        else
                        {
                            this.CBSysMenu.Checked = true;
                        }
                        if (!(reader["ManagSysSet"].ToString() == "Y"))
                        {
                            this.CBSysSet.Checked = false;
                        }
                        else
                        {
                            this.CBSysSet.Checked = true;
                        }
                        if (reader["ManagFolder"].ToString() == "Y")
                        {
                            this.CBGradeFolder.Checked = true;
                        }
                        else
                        {
                            this.CBGradeFolder.Checked = false;
                        }
                        if (!(reader["ManagPower"].ToString() == "Y"))
                        {
                            this.CBUserPower.Checked = false;
                        }
                        else
                        {
                            this.CBUserPower.Checked = true;
                        }
                    }
                }
                reader.Close();
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
            catch
            {
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString;
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"]);
                if (!base.IsPostBack)
                {
                    base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    base.Response.Cache.SetNoStore();
                    if (this.publicFun_0.ReturnPaperData() == "Yes")
                    {
                        if (this.int_0 != 0)
                        {
                            this.method_0();
                        }
                        if (this.publicFun_0.GetValues("select ManagPower from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ManagPower") != "Y")
                        {
                            this.butDefault.Visible = false;
                        }
                    }
                    else
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

